package com.guang.listener.demo4;

import com.guang.listener.entity.MyEntity;
import com.guang.listener.event.MyEntityEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

/**
 * @Title: MyEntityListener
 * @Author liguang
 * @Package com.guang.listener.listener
 * @Date 2024/11/15 10:37
 * @description: 使用接口来对事件进行监听
 */
@Component
@Slf4j
public class MyEntityDemo4Listener {


    // 默认是同步事件，断点打在这里，默认不会继续向下继续执行
    @EventListener
    @Async(value = "testListenExecutor")
    public void onApplicationEvent(MyEntityEvent event) {
        log.info("监听到了event事件");
        Object source = event.getSource();
        MyEntity myEntity = (MyEntity) source;
        log.info("监听到的实体信息为：{}",myEntity);
        log.info("打印当前线程名称：{}",Thread.currentThread().getName());
    }
}
